﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tool;
using CommonTool;

namespace AutoMachine
{
    public partial class Frm_Alarm : Form
    {

        Tool.AutoResize FormResize = new AutoResize();

        public Frm_Alarm()
        {
            InitializeComponent();
            //CommonTool.LogView.GetInstance().SetWarnDataGridView(this.dataGridView_current);
            //CommonTool.LogView.GetInstance().WarnEvent += OnWarnView;
        }

        #region 窗体实例化
        /// <summary>
        /// 窗体实例化
        /// </summary>
        private static Frm_Alarm _instance;
        public static Frm_Alarm Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                    _instance = new Frm_Alarm();
                return _instance;
            }
        }
        #endregion

        private void Frm_Alarm_Load(object sender, EventArgs e)
        { 
            FormResize.SetAutoResize(this);//窗体缩放实例化    
        }      

        public void OnWarnView(string strLog)
        {
            this.BeginInvoke((MethodInvoker)delegate
            {
                DateTime now = DateTime.Now;
                string Date = now.ToString("yyyy-MM-dd");
                string Time = now.ToString("HH:mm:ss");
                dataGridView_current.Rows.Add();
                int i = dataGridView_current.Rows.Count - 1;
                dataGridView_current.Rows[i].Cells[0].Value = Date;//日期
                dataGridView_current.Rows[i].Cells[1].Value = Time;//时间
                dataGridView_current.Rows[i].Cells[2].Value = strLog;//内容
                dataGridView_current.CurrentCell = dataGridView_current[0, i]; // 强制将光标指向i行
                dataGridView_current.Rows[i].Selected = true;   //光标显示至i行
                if (i > 500)
                {
                    dataGridView_current.Rows.Clear();
                }
            });
        }

        private void 数据清除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.dataGridView_current.Rows.Clear();
        }
    }
}
